﻿
Imports System.Reflection
Imports System.Globalization
Imports System.ComponentModel
Imports System.Data.SqlClient

Imports System.IO
Imports System.Collections.Generic

Imports DataAccessLayer
Imports Gurusoft.Components
Imports Microsoft.ApplicationBlocks.Data

Public Class frmACAD

    ' Fields
    Private m_sPrename As String = String.Empty
    Private m_sName As String = String.Empty
    Private m_sSname As String = String.Empty

    Private m_sPrename2 As String = String.Empty
    Private m_sName2 As String = String.Empty
    Private m_sSname2 As String = String.Empty
    Private m_sID As String = String.Empty
    Private pTransferData As TransferData = New TransferData
    Private pTranscourseno As New Gurosoft.DAL.Transcourseno

    Private m_bGo As Boolean = False

    ' Function 
    Private Function GetConnection() As SqlClient.SqlConnection
        Dim connection As New SqlConnection

        Try
            Dim sConnectionString As String = Transfer.My.MySettings.Default.TransferConnectionString.ToString()
            connection = New SqlClient.SqlConnection(sConnectionString)
            connection.Open()

        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

        Return connection
    End Function

    Private Sub Out_TranscriptBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Out_TranscriptBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Out_TranscriptBindingSource.EndEdit()
        Me.Out_TranscriptTableAdapter.Update(Me.TransferDataSet.Out_Transcript)
    End Sub

    Private Sub frmOut_Transcript_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadYear()
            LoadTerm()
            Me.Out_TranscriptTableAdapter.Fill(Me.TransferDataSet.Out_Transcript)
            'Me.YearComboBox.Text = Me.YearTextBox.Text
            Me.Out_TranscriptDataGridView.Rows(0).Selected = True
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnLookup3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLookup3.Click
        Me.Cursor = Cursors.WaitCursor
        Dim frm As New frmLookup
        frm.LookupType = "Bulletin"

        If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.CoursenoTextBox.Text = frm.CourseNo
            Me.txtTitle.Text = frm.Title
            Me.CreditTextBox.Text = frm.Credit
            'Me.txtCrelec.Text = frm.Crelec
            'Me.txtCrelab.Text = frm.Crelab
        End If
        Me.Cursor = Cursors.Default
    End Sub

    ' Display year information
    Private Sub LoadYear()
        With YearComboBox
            .Items.Add("")
            .Items.Add((DateTime.Today.Year - 4) + 543)
            .Items.Add((DateTime.Today.Year - 3) + 543)
            .Items.Add((DateTime.Today.Year - 2) + 543)
            .Items.Add((DateTime.Today.Year - 1) + 543)
            .Items.Add((DateTime.Today.Year) + 543)
            .Items.Add((DateTime.Today.Year + 1) + 543)
            .Items.Add((DateTime.Today.Year + 2) + 543)
            .Items.Add((DateTime.Today.Year + 3) + 543)
            .Items.Add((DateTime.Today.Year + 4) + 543)
        End With
    End Sub

    ' Displays term information
    Private Sub LoadTerm()
        With TermComboBox
            .Items.Add("")
            .Items.Add(1)
            .Items.Add(2)
            .Items.Add(3)
        End With
    End Sub

    Private Sub btnId_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnId.Click
        Me.Cursor = Cursors.WaitCursor
        Dim frm As New frmLookup
        frm.LookupType = "Master"

        If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.IdTextBox.Text = frm.ID

            'Me.CoursenoTextBox.Text = frm.CourseNo
            'Me.txtTitle.Text = frm.Title
            'Me.txtCredit.Text = frm.Credit
        End If
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub IdTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdTextBox.TextChanged
        If Me.IdTextBox.Text.Length = 0 Then Exit Sub

        'SqlDataReader that will hold the returned results		
        Dim dr As SqlClient.SqlDataReader = Nothing

        'SqlConnection that will be used to execute the sql commands
        Dim connection As SqlClient.SqlConnection = Nothing

        Try
            Try
                connection = GetConnection()
            Catch ex As Exception
                MessageBox.Show("The connection with the database canดt be established", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End Try

            ' Set up parameters 
            Dim arParms() As SqlParameter = New SqlParameter(7) {}

            ' @Id Input Parameter  
            arParms(0) = New SqlParameter("@id", SqlDbType.Int)
            arParms(0).Value = Me.IdTextBox.Text.ToString()

            ' @prename Output Parameter  
            arParms(1) = New SqlParameter("@prename", SqlDbType.NVarChar, 20)
            arParms(1).Direction = ParameterDirection.Output

            ' @name Output Parameter  
            arParms(2) = New SqlParameter("@name", SqlDbType.NVarChar, 18)
            arParms(2).Direction = ParameterDirection.Output

            ' @sname Output Parameter  
            arParms(3) = New SqlParameter("@sname", SqlDbType.NVarChar, 21)
            arParms(3).Direction = ParameterDirection.Output

            ' @faculty Output Parameter 
            arParms(4) = New SqlParameter("@faculty", SqlDbType.NVarChar, 35)
            arParms(4).Direction = ParameterDirection.Output

            arParms(5) = New SqlParameter("@major", SqlDbType.NVarChar, 2)
            arParms(5).Direction = ParameterDirection.Output

            arParms(6) = New SqlParameter("@major_name", SqlDbType.NVarChar, 100)
            arParms(6).Direction = ParameterDirection.Output

            'Call ExecuteNonQuery static method of SqlHelper class
            'We pass in database connection string, command type, stored procedure name and an array of SqlParameter objects

            SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, "getMaster", arParms)

            If arParms(1).Value.ToString = "" Then
                Exit Sub
            Else
                Me.txtFullName.Text = String.Format("{0}", arParms(2).Value.ToString() + " " + arParms(3).Value.ToString())

                'Dim sDesc As String = String.Format("{0} {1} {2}", arParms(1).Value, arParms(2).Value, arParms(3).Value)

                'Me.PrenameTextBox.Text = arParms(1).Value.ToString()
                'Me.NameTextBox.Text = arParms(2).Value.ToString()
                'Me.SnameTextBox.Text = arParms(3).Value.ToString()

                'Dim sFaculty As String = arParms(4).Value.ToString()
                'Dim sMajor As String = arParms(5).Value.ToString()
                'Dim sMajor_Name As String = arParms(6).Value.ToString()

                'Me.txtDesc.Text = PrenameTextBox.Text + " " + NameTextBox.Text + " " + SnameTextBox.Text
                'Me.txtFaculty.Text = sFaculty
                'Me.txtMajor_Id1.Text = sMajor
                'Me.txtMajor.Text = sMajor_Name
            End If

            ''iterate through SqlDataReader
            'While dr.Read()
            '    'get the value of second column in the datareader (product description)
            '    'txtResults.Text = txtResults.Text + dr.GetValue(1) + Environment.NewLine
            '    MessageBox.Show(dr.GetValue(1))
            'End While

        Catch ex As Exception
            Dim errMessage As String = ""
            Dim tempException As Exception = ex

            While (Not tempException Is Nothing)
                errMessage += tempException.Message + Environment.NewLine + Environment.NewLine
                tempException = tempException.InnerException
            End While

            MessageBox.Show(String.Format("There are some problems while trying to use the Data Access Application block, please check the following error messages: {0}" _
              + Environment.NewLine + "This test requires some modifications to the Transfer database.", errMessage), _
              "Application error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If Not dr Is Nothing Then
                CType(dr, IDisposable).Dispose()
            End If

            If Not connection Is Nothing Then
                CType(connection, IDisposable).Dispose()
            End If
        End Try
    End Sub

    Private Sub CoursenoTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CoursenoTextBox.TextChanged
        If CoursenoTextBox.Text.Length = 0 Then Exit Sub

        'SqlDataReader that will hold the returned results		
        Dim dr As SqlClient.SqlDataReader = Nothing

        'SqlConnection that will be used to execute the sql commands
        Dim connection As SqlClient.SqlConnection = Nothing

        Try
            Try
                connection = GetConnection()
            Catch ex As Exception
                MessageBox.Show("The connection with the database can't be established", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End Try

            ' Set up parameters (1 input and 3 output) 
            Dim arParms() As SqlParameter = New SqlParameter(2) {}

            ' @Id Input Parameter  
            arParms(0) = New SqlParameter("@coursno", SqlDbType.NVarChar, 6)
            arParms(0).Value = CoursenoTextBox.Text.ToString

            ' @prename Output Parameter  
            arParms(1) = New SqlParameter("@title", SqlDbType.NVarChar, 30)
            arParms(1).Direction = ParameterDirection.Output

            ' @name Output Parameter  
            arParms(2) = New SqlParameter("@credit", SqlDbType.NVarChar, 15)
            arParms(2).Direction = ParameterDirection.Output

            'Call ExecuteNonQuery static method of SqlHelper class
            'We pass in database connection string, command type, stored procedure name and an array of SqlParameter objects

            SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, "getBulletin", arParms)

            'If arParms(1).Value.ToString = "" Then
            '    Exit Sub
            'Else
            'Dim sDesc As String = String.Format("{0} {1} {2}", arParms(1).Value, arParms(2).Value, arParms(3).Value)

            Dim sCoursno As String = arParms(0).Value.ToString()
            Dim sTitle As String = arParms(1).Value.ToString()
            Dim sCredit As String = arParms(2).Value.ToString()

            Me.CoursenoTextBox.Text = sCoursno
            Me.txtTitle.Text = sTitle

            'Me.CreditTextBox.Text = sCredit

            'End If

        Catch ex As Exception
            Dim errMessage As String = ""
            Dim tempException As Exception = ex

            While (Not tempException Is Nothing)
                errMessage += tempException.Message + Environment.NewLine + Environment.NewLine
                tempException = tempException.InnerException
            End While

            MessageBox.Show(String.Format("There are some problems while trying to use the Data Access Application block, please check the following error messages: {0}" _
              + Environment.NewLine + "This test requires some modifications to the Transfer database.", errMessage), _
              "Application error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If Not dr Is Nothing Then
                CType(dr, IDisposable).Dispose()
            End If

            If Not connection Is Nothing Then
                CType(connection, IDisposable).Dispose()
            End If
        End Try
    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
        Me.IdTextBox.Focus()
        Me.txtFullName.Text = String.Empty
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MessageBox.Show("คุณแน่ใจที่จะลบรายการนี้ใช่หรือไม่?", "ลบข้อมูล", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            Out_TranscriptBindingSource.RemoveCurrent()
            Out_TranscriptBindingNavigatorSaveItem_Click(sender, e)
        End If
    End Sub

    Private Sub Out_TranscriptBindingNavigatorCancelItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Out_TranscriptBindingNavigatorCancelItem.Click
        Out_TranscriptBindingSource.CancelEdit()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub btnImportTOdbf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportTOdbf.Click
        Try
            CheckTransferFromDB()
        Catch ex As Exception
            DisplayErrorDialog(ex)
        End Try
    End Sub

    ' Displays dialog with information about exceptions that occur in the application. 
    Private Sub DisplayErrorDialog(ByVal ex As Exception)
        Dim errorMsg As String = String.Format(My.Resources.Culture, My.Resources.GeneralExceptionMessage, ex.Message)

        errorMsg += Environment.NewLine + My.Resources.DbRequirementsMessage

        Dim result As DialogResult = System.Windows.Forms.MessageBox.Show(errorMsg, My.Resources.ApplicationErrorMessage, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop)

        ' Exits the program when the user clicks Abort.
        If (result = System.Windows.Forms.DialogResult.Abort) Then
            Application.Exit()
        End If
        Cursor = System.Windows.Forms.Cursors.Default
    End Sub

    Private Sub CheckTransferFromDB()

        If Me.IdTextBox.Text.Length = 0 Then Exit Sub

        'SqlConnection that will be used to execute the sql commands
        Dim connection As SqlClient.SqlConnection = Nothing

        Try
            connection = GetConnection()
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show("The connection with the database can't be established", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

        ' Set up parameters
        Dim arParms() As SqlParameter = New SqlParameter(1) {}

        ' @Id Input Parameter  
        arParms(0) = New SqlParameter("@id", SqlDbType.Int)
        arParms(0).Value = Me.IdTextBox.Text.ToString().Trim
        arParms(1) = New SqlParameter("@courseno", SqlDbType.NVarChar)
        arParms(1).Value = Me.CoursenoTextBox.Text.ToString().Trim

        Dim ds As New DataSet
        ds = SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "sp_CheckTransfer4", arParms)

        If ds.Tables(0).Rows.Count = 0 Then
            System.Windows.Forms.MessageBox.Show("ไม่พบข้อมูลใน transcourseno table", "แจ้งให้ทราบ", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        Else
            ' Compare id with dbf file.            
            Dim sFoxPath As String = Transfer.My.MySettings.Default.FoxPath.ToString()
            Dim sIdFileName As String = String.Format("{0}{1}{2}", "acad", Me.IdTextBox.Text.Substring(2, 2).ToString, ".dbf")
            Dim sFullPath As String = String.Format("{0}{1}", sFoxPath, sIdFileName)
            Dim nFile As Integer = CInt(Me.IdTextBox.Text.Substring(2, 2))

            If nFile > 21 Then
                System.Windows.Forms.MessageBox.Show("การค้นหาข้อมูลต้องไม่เกินไฟล์ที่ 21", "แจ้งให้ทราบ", _
                MessageBoxButtons.OK, MessageBoxIcon.Warning)
                progressBarEx1.Visible = False
                Cursor = Cursors.Default
                Exit Sub
            End If

            If (System.Windows.Forms.MessageBox.Show("เริ่มค้นหาข้อมูลใน FoxPro " + vbNewLine + "File location " + sFullPath, "แจ้งให้ทราบ", _
                MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK) Then

                m_bGo = True
                progressBarEx1.Visible = True
                progressBarEx1.Value = 0
                progressBarEx1.Maximum = 10000
                Cursor = Cursors.WaitCursor

                Dim dtNew As New DataTable
                For Each dtx As DataRow In ds.Tables(0).Rows

                    Dim sId As String = dtx("id").ToString().Trim()
                    Dim sTitle As String = dtx("title").ToString().Trim()
                    'Dim sOldDetail As String = dtx(2).ToString().Trim()
                    Dim sCourseNo As String = dtx("courseno").ToString().Trim()
                    Dim sCredit As String = dtx("credit").ToString().Trim()
                    Dim sTerm As Integer = dtx("term").ToString().Trim()
                    Dim sYear As String = dtx("year").ToString().Trim()
                    Dim sTrm As String = dtx("trm").ToString().Trim()
                    Dim sStatus As String = dtx("status").ToString().Trim()

                    ' Check transfered data to FoxPro
                    Dim bNotTransfered As Boolean = Me.GetTransfered_Out(CInt(Me.IdTextBox.Text), sCourseNo)
                    If bNotTransfered = False Then Exit For

                    If sStatus = "" Then
                        ' Get courseno and grade is not null : filter
                        Dim sCriteria As String = String.Empty

                        Try
                            ' Check data before insert to dbf and sql server.
                            Dim nResult As Integer = InsertDB(Me.IdTextBox.Text, sCourseNo, sTitle, sCredit, sTrm)

                            For i As Integer = 0 To progressBarEx1.Maximum - 1
                                If Not m_bGo Then
                                    Exit For
                                End If
                                progressBarEx1.Value = i
                                Application.DoEvents()
                            Next

                            If nResult > 0 Then

                                ' Update status Out_Transcript
                                'Dim rowsAfferted As Integer = pTransferData.UpdateOut_Transcript(Me.IdTextBox.Text, sCourseNo, "Transfered")

                                'Me.Validate()
                                'Me.Out_TranscriptBindingSource.EndEdit()
                                Me.Out_TranscriptTableAdapter.UpdateQuery("Transfered", Me.IdTextBox.Text, sCourseNo)

                                System.Windows.Forms.MessageBox.Show("บันทึกข้อมูลลง FoxPro  " & nResult & " รายการ ")
                            End If

                        Catch ex As Exception
                            DisplayErrorDialog(ex)
                        End Try
                    Else
                        System.Windows.Forms.MessageBox.Show("ข้อมูลได้ทำการ Transfer เสร็จเรียบร้อยแล้ว", "แจ้งให้ทราบ", _
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
                        progressBarEx1.Visible = False
                        Cursor = Cursors.Default
                        Exit Sub
                    End If

                    'progressBarEx1.Value = 0;
                    progressBarEx1.Visible = False

                Next
                Cursor = Cursors.Default
            End If
        End If
    End Sub

    Private Function InsertDB(ByVal sIdTextBox As String, ByVal sCourseNo As String, ByVal sTitle As String, _
                              ByVal sCredit As String, ByVal sTrm As String) As Integer

        ' Compare id with dbf file.            
        Dim sFoxPath As String = Transfer.My.MySettings.Default.FoxPath.ToString()
        Dim sIdFileName As String = String.Format("{0}{1}{2}", "acad", Me.IdTextBox.Text.Substring(2, 2).ToString, ".dbf")
        Dim sFullPath As String = String.Format("{0}{1}", sFoxPath, sIdFileName)

        Try
            Cursor = Cursors.WaitCursor

            Dim sStatus As String = "O"
            Dim sGrades As String = IIf(Me.GradeTextBox.Text <> "", GradeTextBox.Text, "")

            ' Insert database to SQL Server (Keep log)
            Dim rowsAffected As Integer = pTransferData.UpdateProducts(sIdTextBox, sCourseNo, sTitle, sCredit, sTrm, sGrades, sStatus, "Manual")

            ' Insert database to FoxPro
            InsertSQLtoDBF(sIdFileName, sFullPath, sIdTextBox, sCredit, sTrm, sCourseNo, sTitle, sGrades, sStatus)

            Return rowsAffected

        Catch ex As Exception
            DisplayErrorDialog(ex)
        Finally
            Cursor = Cursors.Arrow
        End Try
    End Function


    ''' <summary>
    ''' Insert SQL server to DBF
    ''' </summary>
    ''' <param name="sIdFileName"></param>
    ''' <param name="sFullPath"></param>
    ''' <param name="sId"></param>
    ''' <param name="sTrm"></param>
    ''' <param name="sCourseNo"></param>
    ''' <param name="sTitle"></param>
    ''' <param name="sGrades"></param>
    ''' <param name="sStatus"></param>
    ''' <remarks></remarks>
    Private Sub InsertSQLtoDBF(ByVal sIdFileName As String, ByVal sFullPath As String, ByVal sId As String, _
                               ByVal sCredit As String, ByVal sTrm As String, _
                               ByVal sCourseNo As String, ByVal sTitle As String, ByVal sGrades As String, ByVal sStatus As String)

        Dim con As New OleDb.OleDbConnection
        Dim da As New OleDb.OleDbDataAdapter
        Dim dsTransfer As New DataSet

        Dim sSQL As String = String.Empty
        Dim sPath As String = String.Empty

        sSQL = String.Format("{0}{1}", "SELECT Id, Trm, CourseNo, Title, Credit, Grade, Status, idold, reg_ipt, seclec, seclab, gradeold FROM ", sIdFileName)
        sPath = String.Format("{0}{1};Persist Security Info=False", "Provider=VFPOLEDB.1;Data Source=", sFullPath)

        con = New OleDb.OleDbConnection(sPath)

        'Dim cmdFox As OleDb.OleDbCommand = New OleDb.OleDbCommand
        Dim daFox As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
        Dim dsFox As DataSet = New DataSet
        Dim ra As Integer

        Dim insertSQL As String = String.Format("INSERT INTO {0} (Id, Trm, CourseNo, Title, Credit, Grade, Status, idold, reg_ipt, seclec, seclab, gradeold) " & _
                                  " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", sIdFileName)

        pTranscourseno = New Gurosoft.DAL.Transcourseno
        pTranscourseno.Id = sId
        pTranscourseno.Trm = sTrm
        pTranscourseno.Courseno = sCourseNo
        pTranscourseno.Title = sTitle
        pTranscourseno.Credit = sCredit
        pTranscourseno.Status = sStatus
        pTranscourseno.Grade = sGrades
        pTranscourseno.IdoId = "-"
        pTranscourseno.Reg_ipt = ""
        pTranscourseno.Seclec = ""
        pTranscourseno.Seclab = ""
        pTranscourseno.Gradeold = ""

        con.Open()

        Dim cmdFox As New OleDb.OleDbCommand(insertSQL, con)
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Id", pTranscourseno.Id))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Trm", pTranscourseno.Trm))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("CourseNo", pTranscourseno.Courseno))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Title", pTranscourseno.Title))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Credit", pTranscourseno.Credit))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Grade", pTranscourseno.Grade))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("Status", pTranscourseno.Status))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("idold", pTranscourseno.IdoId))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("reg_ipt", pTranscourseno.Reg_ipt))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("seclec", pTranscourseno.Seclec))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("seclab", pTranscourseno.Seclab))
        cmdFox.Parameters.Add(New OleDb.OleDbParameter("gradeold", pTranscourseno.Gradeold))

        ra = cmdFox.ExecuteNonQuery()

        'System.Windows.Forms.MessageBox.Show("บันทึกข้อมูลลง FoxPro " & ra & " รายการ ")

        dsFox.Dispose()
        daFox.Dispose()
        cmdFox.Dispose()
        con.Close()
    End Sub

    Private Function ConnectDBF(ByVal sFullPath As String) As DataSet
        Dim ds As DataSet = New DataSet
        Dim con As New OleDb.OleDbConnection

        Dim sSQL As String = String.Empty
        Dim sPath As String = String.Empty
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

        Try
            ' Compare id with dbf file.            
            Dim sFoxPath As String = Transfer.My.MySettings.Default.FoxPath.ToString()
            Dim sIdFileName As String = String.Format("{0}{1}{2}", "acad", Me.IdTextBox.Text.Substring(2, 2).ToString, ".dbf")
            'Dim sFullPath As String = String.Format("{0}{1}", sFoxPath, sIdFileName)

            sSQL = String.Format("{0}{1}", "SELECT * FROM ", sIdFileName)
            sPath = String.Format("{0}{1};Persist Security Info=False;Exclusive=No", "Provider=VFPOLEDB.1;Data Source=", sFullPath)

            con = New OleDb.OleDbConnection(sPath)
            con.Open()

            da = New OleDb.OleDbDataAdapter(sSQL, con)
            da.Fill(ds, "MyTable")

        Catch ex As Exception
            DisplayErrorDialog(ex)
        Finally
            ' Dispose
            da.Dispose()
            ds.Dispose()
            con.Dispose()
        End Try

        Return ds
    End Function

    Private Function GetTransfered_Out(ByVal nId As Integer, ByVal sCourseNo As String) As Boolean

        Dim ds As New DataSet
        Try
            Cursor = Cursors.WaitCursor
            ds = pTransferData.GetTransfered_Out(nId, sCourseNo)
            Cursor = Cursors.Default

            If ds.Tables(0).Rows.Count > 0 Then
                System.Windows.Forms.MessageBox.Show("ไม่สามารถ ทำการเพิ่มข้อมูลได้", "เตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return False
            Else
                Return True
            End If

        Catch ex As Exception
            DisplayErrorDialog(ex)
        Finally
            Cursor = Cursors.Arrow
        End Try

        Return False
    End Function


    Private Sub Out_TranscriptBindingNavigator_RefreshItems(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Out_TranscriptBindingNavigator.RefreshItems

    End Sub
End Class